# -*- coding:utf-8 -*-
from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
from django.views.generic import list_detail, create_update
from django.shortcuts import get_object_or_404
from agt2.models import Game, Squad, Unit, Task, Hint, Key
from django import forms
from django.contrib.admin.widgets import *

admin.autodiscover()

def games_detail (request, game_id):
    game = get_object_or_404(Game, pk=game_id)
    
    return list_detail.object_detail(
        request,
        queryset = Game.objects.all(),
        object_id = game_id,
    )

class GameForm(forms.ModelForm):
    class Meta:
        model = Game

    start_timestamp = forms.DateTimeField(widget=AdminSplitDateTime)
    end_timestamp   = forms.DateTimeField(widget=AdminSplitDateTime)

urlpatterns = patterns('',
    (r'^static/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': '../static'}),
    (r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'agt2/login.html'}),
    (r'^logout/$', 'django.contrib.auth.views.logout', {'next_page': '/'}),
    (r'^games/$', list_detail.object_list, { "queryset" : Game.objects.all() }),

    (r'^profile/(?P<object_id>\d+)/$', list_detail.object_detail, { 'queryset' : Unit.objects.all(), 'template_name' : 'agt2/user_detail.html' }),
    (r'^profile/create$', create_update.create_object, { 'model' : Unit }),

    (r'^squad/create$', create_update.create_object, {'model' : Squad, 'login_required' : True}),
    (r'^squad/(?P<object_id>\d+)/$', list_detail.object_detail, { 'queryset' : Squad.objects.all() }),
    (r'^squads/$', list_detail.object_list,  { "queryset" : Squad.objects.all() }),

    )

urlpatterns += patterns('agt2.views',
    (r'^$', 'index'),

    (r'^author/games$', 'my_author_games'),
    (r'^author/game/(?P<game_id>\d+)/scenario$', 'author_game_scenario'),
    (r'^author/game/(?P<game_id>\d+)/scenario/task/create$', 'scenario_task_create'),
#    (r'^author/game/scenario/task/(?P<task_id>\d+)/([update|delete])$', 'scenario_task_create'),
#    (r'^author/game/scenario/task/(?P<task_id>\d+)/key/([create|update|delete])$', 'scenario_key'),
#    (r'^author/game/scenario/task/(?P<task_id>\d+)/hint/([create|update|delete])$', 'scenario_hint'),
#    (r'^author/game/(?P<game_id>\d+)/participate_requests$', 'author_game_scenario'),
    (r'^author/game/(?P<object_id>\d+)/announce$', create_update.update_object, { 'form_class' : GameForm, 'post_save_redirect' : '/author/game/%(id)s/announce' }),
#    (r'^author/game/create$', create_update.create_object, { 'model' : Game }),

    (r'^profile/$', 'my_profile_update'),
    (r'^profile/delete$', 'my_profile_delete'),

    (r'^squad/$', 'my_squad_update'),
    (r'^squad/delete$', 'my_squad_delete'),

    (r'^squad/(?P<object_id>\d+)/request$', 'squad_request_create'),
    (r'^squads/request/(?P<object_id>\d+)/([accept|decline])', 'squad_request_update'),

# просмотр анонса и подача заявки на игру
    (r'^game/(?P<game_id>\d+)/$', games_detail),
#    (r'^game/(?P<game_id>\d+)/request$', ),
#    (r'^game/(?P<game_id>\d+)/enter$', ),

    (r'^admin/', include(admin.site.urls)),
)


